package app.android.kdictionary.Activity;

import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import app.android.kdictionary.R;
import app.android.kdictionary.R.id;


public class OtherSelectActivity extends DefaultActivity {
	private ImageButton idiomButton;	// 관용
	private ImageButton adageButton;	// 속담
	private ImageButton dialectButton;	// 방언 
	private ImageButton nKoreaButton;	// 북한어
	private ImageButton nativeButton;	// 고유어
	
	private SharedPreferences sharedPreferences;
	private SharedPreferences.Editor sharedEditor;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.other_select);
        
        findView();
        setListener();
        init();
    }

	private void findView() {
		idiomButton = (ImageButton)findViewById(id.Main_Ohter_01);
		adageButton = (ImageButton)findViewById(id.Main_Ohter_02);
		dialectButton = (ImageButton)findViewById(id.Main_Ohter_03);
		nKoreaButton = (ImageButton)findViewById(id.Main_Ohter_04);
		nativeButton = (ImageButton)findViewById(id.Main_Ohter_05);
	}
	
	private void setListener() {
		idiomButton.setOnClickListener(mIdiomClickListener);
		adageButton.setOnClickListener(mAdageClickListener);
		dialectButton.setOnClickListener(mDialectClickListener);
		nKoreaButton.setOnClickListener(mNKoreaClickListener);
		nativeButton.setOnClickListener(mNativeClickListener);
	}
	
	private void init() {
		sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    	sharedEditor = sharedPreferences.edit();
	}

    private OnClickListener mIdiomClickListener = new OnClickListener() {
        public void onClick(View v) {
        	Intent startIntent  = new Intent(getBaseContext(), OtherActivity.class);
        	sharedEditor.putString("type", "IDIOM");
        	sharedEditor.commit();
			PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
			try {
				pendingIntent.send();
			} catch( CanceledException e ) {
				e.printStackTrace();
			}
        }
    };
    
    private OnClickListener mAdageClickListener = new OnClickListener() {
        public void onClick(View v) {
        	Intent startIntent  = new Intent(getBaseContext(), OtherActivity.class);
        	sharedEditor.putString("type", "ADAGE");
        	sharedEditor.commit();
        	PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
			try {
				pendingIntent.send();
			} catch( CanceledException e ) {
				e.printStackTrace();
			}
        }
    };
    
    private OnClickListener mDialectClickListener = new OnClickListener() {
        public void onClick(View v) {
        	Intent startIntent  = new Intent(getBaseContext(), OtherActivity.class);
        	sharedEditor.putString("type", "DIALECT");
        	sharedEditor.commit();
        	PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, startIntent, 0);
			try {
				pendingIntent.send();
			} catch( CanceledException e ) {
				e.printStackTrace();
			}
        }
    };
    
    private OnClickListener mNKoreaClickListener = new OnClickListener() {
        public void onClick(View v) {
        	Intent startIntent  = new Intent(getBaseContext(), OtherActivity.class);
        	sharedEditor.putString("type", "NKOREA");
        	sharedEditor.commit();
			PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
			try {
				pendingIntent.send();
			} catch( CanceledException e ) {
				e.printStackTrace();
			}
        }
    };
    
    private OnClickListener mNativeClickListener = new OnClickListener() {
        public void onClick(View v) {
        	Intent startIntent = new Intent(getBaseContext(), OtherActivity.class);
        	sharedEditor.putString("type", "NATIVE");
        	sharedEditor.commit();
			PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
			try {
				pendingIntent.send();
			} catch( CanceledException e ) {
				e.printStackTrace();
			}
        }
    };
}
